.class public Lcom/htc/android/footprints/backup/FootprintRestoreService;
.super Lcom/htc/util/backup/BackupRestoreService;
.source "FootprintRestoreService.java"


# static fields
.field private static final FILE_NAME:Ljava/lang/String; = "footprints_backup.kmz"

.field private static final TAG:Ljava/lang/String; = "FootprintRestoreService"


# instance fields
.field private filepath:Ljava/lang/String;


# direct methods
.method public constructor <init>()V
    .locals 0

    .prologue
    .line 22
    invoke-direct {p0}, Lcom/htc/util/backup/BackupRestoreService;-><init>()V

    return-void
.end method


# virtual methods
.method public convertData(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V
    .locals 16
    .parameter "model"
    .parameter "restoreVersion"
    .parameter "filename"

    .prologue
    .line 79
    move-object/from16 v0, p0

    iget-object v0, v0, Lcom/htc/android/footprints/backup/FootprintRestoreService;->mVersion:Ljava/lang/String;

    move-object v13, v0

    invoke-static {v13}, Lcom/htc/util/backup/Version;->parse(Ljava/lang/String;)Lcom/htc/util/backup/Version;

    move-result-object v3

    .line 80
    .local v3, currentVersion:Lcom/htc/util/backup/Version;
    invoke-static/range {p2 .. p2}, Lcom/htc/util/backup/Version;->parse(Ljava/lang/String;)Lcom/htc/util/backup/Version;

    move-result-object v10

    .line 81
    .local v10, resVersion:Lcom/htc/util/backup/Version;
    sget-object v13, Ljava/io/File;->separator:Ljava/lang/String;

    move-object/from16 v0, p3

    move-object v1, v13

    invoke-virtual {v0, v1}, Ljava/lang/String;->lastIndexOf(Ljava/lang/String;)I

    move-result v13

    add-int/lit8 v13, v13, 0x1

    move-object/from16 v0, p3

    move v1, v13

    invoke-virtual {v0, v1}, Ljava/lang/String;->substring(I)Ljava/lang/String;

    move-result-object v11

    .line 83
    .local v11, restoreFile:Ljava/lang/String;
    invoke-virtual {v11}, Ljava/lang/String;->toLowerCase()Ljava/lang/String;

    move-result-object v13

    const-string v14, "footprints_backup.kmz"

    invoke-virtual {v13, v14}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v13

    if-eqz v13, :cond_1

    .line 84
    invoke-virtual {v10, v3}, Lcom/htc/util/backup/Version;->lessEqualThan(Lcom/htc/util/backup/Version;)Z

    move-result v13

    if-eqz v13, :cond_1

    .line 85
    const/4 v6, 0x0

    .line 87
    .local v6, fi:Ljava/io/FileInputStream;
    :try_start_0
    new-instance v7, Ljava/io/FileInputStream;

    move-object v0, v7

    move-object/from16 v1, p3

    invoke-direct {v0, v1}, Ljava/io/FileInputStream;-><init>(Ljava/lang/String;)V
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_1

    .line 90
    .end local v6           #fi:Ljava/io/FileInputStream;
    .local v7, fi:Ljava/io/FileInputStream;
    :try_start_1
    invoke-virtual/range {p0 .. p0}, Lcom/htc/android/footprints/backup/FootprintRestoreService;->getApplicationContext()Landroid/content/Context;

    move-result-object v13

    invoke-static {v13}, Lcom/htc/android/footprints/provider/FootprintManager;->getInstance(Landroid/content/Context;)Lcom/htc/android/footprints/provider/FootprintManager;

    move-result-object v13

    invoke-virtual {v13}, Lcom/htc/android/footprints/provider/FootprintManager;->removeAllFootprint()V

    .line 94
    invoke-static {v7}, Lcom/htc/android/footprints/kml/KMLUtil;->importKMZ(Ljava/io/InputStream;)[Lcom/htc/android/footprints/vo/Footprint;

    move-result-object v12

    .line 95
    .local v12, result:[Lcom/htc/android/footprints/vo/Footprint;
    move-object v2, v12

    .local v2, arr$:[Lcom/htc/android/footprints/vo/Footprint;
    array-length v9, v2

    .local v9, len$:I
    const/4 v8, 0x0

    .local v8, i$:I
    :goto_0
    if-ge v8, v9, :cond_0

    aget-object v5, v2, v8

    .line 96
    .local v5, f:Lcom/htc/android/footprints/vo/Footprint;
    invoke-virtual/range {p0 .. p0}, Lcom/htc/android/footprints/backup/FootprintRestoreService;->getApplicationContext()Landroid/content/Context;

    move-result-object v13

    invoke-static {v13}, Lcom/htc/android/footprints/provider/FootprintManager;->getInstance(Landroid/content/Context;)Lcom/htc/android/footprints/provider/FootprintManager;

    move-result-object v13

    invoke-virtual {v13, v5}, Lcom/htc/android/footprints/provider/FootprintManager;->addFootprint(Lcom/htc/android/footprints/vo/Footprint;)I
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_3

    .line 95
    add-int/lit8 v8, v8, 0x1

    goto :goto_0

    .line 103
    .end local v5           #f:Lcom/htc/android/footprints/vo/Footprint;
    :cond_0
    if-eqz v7, :cond_1

    .line 105
    :try_start_2
    invoke-virtual {v7}, Ljava/io/FileInputStream;->close()V
    :try_end_2
    .catch Ljava/io/IOException; {:try_start_2 .. :try_end_2} :catch_0

    .line 113
    .end local v2           #arr$:[Lcom/htc/android/footprints/vo/Footprint;
    .end local v7           #fi:Ljava/io/FileInputStream;
    .end local v8           #i$:I
    .end local v9           #len$:I
    .end local v12           #result:[Lcom/htc/android/footprints/vo/Footprint;
    :cond_1
    :goto_1
    return-void

    .line 106
    .restart local v2       #arr$:[Lcom/htc/android/footprints/vo/Footprint;
    .restart local v7       #fi:Ljava/io/FileInputStream;
    .restart local v8       #i$:I
    .restart local v9       #len$:I
    .restart local v12       #result:[Lcom/htc/android/footprints/vo/Footprint;
    :catch_0
    move-exception v4

    .line 107
    .local v4, e:Ljava/io/IOException;
    const-string v13, "FootprintRestoreService"

    invoke-virtual {v4}, Ljava/io/IOException;->getMessage()Ljava/lang/String;

    move-result-object v14

    invoke-static {v13, v14, v4}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :goto_1

    .line 100
    .end local v2           #arr$:[Lcom/htc/android/footprints/vo/Footprint;
    .end local v4           #e:Ljava/io/IOException;
    .end local v7           #fi:Ljava/io/FileInputStream;
    .end local v8           #i$:I
    .end local v9           #len$:I
    .end local v12           #result:[Lcom/htc/android/footprints/vo/Footprint;
    .restart local v6       #fi:Ljava/io/FileInputStream;
    :catch_1
    move-exception v13

    move-object v4, v13

    .line 101
    .local v4, e:Ljava/lang/Exception;
    :goto_2
    :try_start_3
    new-instance v13, Ljava/lang/RuntimeException;

    invoke-direct {v13, v4}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/Throwable;)V

    throw v13
    :try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_0

    .line 103
    .end local v4           #e:Ljava/lang/Exception;
    :catchall_0
    move-exception v13

    :goto_3
    if-eqz v6, :cond_2

    .line 105
    :try_start_4
    invoke-virtual {v6}, Ljava/io/FileInputStream;->close()V
    :try_end_4
    .catch Ljava/io/IOException; {:try_start_4 .. :try_end_4} :catch_2

    .line 108
    :cond_2
    :goto_4
    throw v13

    .line 106
    :catch_2
    move-exception v4

    .line 107
    .local v4, e:Ljava/io/IOException;
    const-string v14, "FootprintRestoreService"

    invoke-virtual {v4}, Ljava/io/IOException;->getMessage()Ljava/lang/String;

    move-result-object v15

    invoke-static {v14, v15, v4}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :goto_4

    .line 103
    .end local v4           #e:Ljava/io/IOException;
    .end local v6           #fi:Ljava/io/FileInputStream;
    .restart local v7       #fi:Ljava/io/FileInputStream;
    :catchall_1
    move-exception v13

    move-object v6, v7

    .end local v7           #fi:Ljava/io/FileInputStream;
    .restart local v6       #fi:Ljava/io/FileInputStream;
    goto :goto_3

    .line 100
    .end local v6           #fi:Ljava/io/FileInputStream;
    .restart local v7       #fi:Ljava/io/FileInputStream;
    :catch_3
    move-exception v13

    move-object v4, v13

    move-object v6, v7

    .end local v7           #fi:Ljava/io/FileInputStream;
    .restart local v6       #fi:Ljava/io/FileInputStream;
    goto :goto_2
.end method

.method public determineAction(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Lcom/htc/util/backup/BackupRestoreService$ActionType;
    .locals 3
    .parameter "restoreModel"
    .parameter "restoreVersion"
    .parameter "restoreFileName"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/Exception;
        }
    .end annotation

    .prologue
    .line 67
    sget-object v1, Ljava/io/File;->separator:Ljava/lang/String;

    invoke-virtual {p3, v1}, Ljava/lang/String;->lastIndexOf(Ljava/lang/String;)I

    move-result v1

    add-int/lit8 v1, v1, 0x1

    invoke-virtual {p3, v1}, Ljava/lang/String;->substring(I)Ljava/lang/String;

    move-result-object v0

    .line 68
    .local v0, restoreFile:Ljava/lang/String;
    const/4 v1, 0x1

    invoke-static {v1}, Lcom/htc/android/footprints/utils/camera/FootprintImageManager;->hasStorage(Z)Z

    move-result v1

    if-eqz v1, :cond_0

    invoke-virtual {v0}, Ljava/lang/String;->toLowerCase()Ljava/lang/String;

    move-result-object v1

    const-string v2, "footprints_backup.kmz"

    invoke-virtual {v1, v2}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v1

    if-eqz v1, :cond_0

    .line 70
    sget-object v1, Lcom/htc/util/backup/BackupRestoreService$ActionType;->CONVERT:Lcom/htc/util/backup/BackupRestoreService$ActionType;

    .line 72
    :goto_0
    return-object v1

    :cond_0
    sget-object v1, Lcom/htc/util/backup/BackupRestoreService$ActionType;->SKIP:Lcom/htc/util/backup/BackupRestoreService$ActionType;

    goto :goto_0
.end method

.method public initBackup()V
    .locals 7

    .prologue
    const-string v6, "FootprintRestoreService"

    .line 31
    const/4 v4, 0x1

    invoke-static {v4}, Lcom/htc/android/footprints/utils/camera/FootprintImageManager;->hasStorage(Z)Z

    move-result v4

    if-eqz v4, :cond_0

    .line 32
    new-instance v4, Ljava/lang/StringBuilder;

    invoke-direct {v4}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {p0}, Lcom/htc/android/footprints/backup/FootprintRestoreService;->getCacheDir()Ljava/io/File;

    move-result-object v5

    invoke-virtual {v5}, Ljava/io/File;->getAbsolutePath()Ljava/lang/String;

    move-result-object v5

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    sget-object v5, Ljava/io/File;->separator:Ljava/lang/String;

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    const-string v5, "footprints_backup.kmz"

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v4

    iput-object v4, p0, Lcom/htc/android/footprints/backup/FootprintRestoreService;->filepath:Ljava/lang/String;

    .line 35
    const/4 v1, 0x0

    .line 37
    .local v1, fo:Ljava/io/FileOutputStream;
    :try_start_0
    new-instance v2, Ljava/io/FileOutputStream;

    iget-object v4, p0, Lcom/htc/android/footprints/backup/FootprintRestoreService;->filepath:Ljava/lang/String;

    invoke-direct {v2, v4}, Ljava/io/FileOutputStream;-><init>(Ljava/lang/String;)V
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_1

    .line 38
    .end local v1           #fo:Ljava/io/FileOutputStream;
    .local v2, fo:Ljava/io/FileOutputStream;
    :try_start_1
    invoke-virtual {p0}, Lcom/htc/android/footprints/backup/FootprintRestoreService;->getApplicationContext()Landroid/content/Context;

    move-result-object v4

    invoke-static {v4}, Lcom/htc/android/footprints/provider/FootprintManager;->getInstance(Landroid/content/Context;)Lcom/htc/android/footprints/provider/FootprintManager;

    move-result-object v4

    const-string v5, "create_time asc"

    invoke-virtual {v4, v5}, Lcom/htc/android/footprints/provider/FootprintManager;->getFootprintAll(Ljava/lang/String;)Ljava/util/ArrayList;

    move-result-object v3

    .line 42
    .local v3, footList:Ljava/util/ArrayList;,"Ljava/util/ArrayList<Lcom/htc/android/footprints/vo/Footprint;>;"
    invoke-virtual {v3}, Ljava/util/ArrayList;->size()I

    move-result v4

    new-array v4, v4, [Lcom/htc/android/footprints/vo/Footprint;

    invoke-virtual {v3, v4}, Ljava/util/ArrayList;->toArray([Ljava/lang/Object;)[Ljava/lang/Object;

    move-result-object v4

    check-cast v4, [Lcom/htc/android/footprints/vo/Footprint;

    invoke-static {v4, v2}, Lcom/htc/android/footprints/kml/KMLUtil;->exportKMZ([Lcom/htc/android/footprints/vo/Footprint;Ljava/io/OutputStream;)V

    .line 46
    invoke-virtual {v2}, Ljava/io/FileOutputStream;->flush()V

    .line 48
    new-instance v4, Ljava/lang/StringBuilder;

    invoke-direct {v4}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {p0}, Lcom/htc/android/footprints/backup/FootprintRestoreService;->getCacheDir()Ljava/io/File;

    move-result-object v5

    invoke-virtual {v5}, Ljava/io/File;->getAbsolutePath()Ljava/lang/String;

    move-result-object v5

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    sget-object v5, Ljava/io/File;->separator:Ljava/lang/String;

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v4

    invoke-virtual {p0, v4}, Lcom/htc/android/footprints/backup/FootprintRestoreService;->addExtraFolder(Ljava/lang/String;)V
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_3

    .line 53
    if-eqz v2, :cond_0

    .line 55
    :try_start_2
    invoke-virtual {v2}, Ljava/io/FileOutputStream;->close()V
    :try_end_2
    .catch Ljava/io/IOException; {:try_start_2 .. :try_end_2} :catch_0

    .line 62
    .end local v2           #fo:Ljava/io/FileOutputStream;
    .end local v3           #footList:Ljava/util/ArrayList;,"Ljava/util/ArrayList<Lcom/htc/android/footprints/vo/Footprint;>;"
    :cond_0
    :goto_0
    return-void

    .line 56
    .restart local v2       #fo:Ljava/io/FileOutputStream;
    .restart local v3       #footList:Ljava/util/ArrayList;,"Ljava/util/ArrayList<Lcom/htc/android/footprints/vo/Footprint;>;"
    :catch_0
    move-exception v0

    .line 57
    .local v0, e:Ljava/io/IOException;
    const-string v4, "FootprintRestoreService"

    invoke-virtual {v0}, Ljava/io/IOException;->getMessage()Ljava/lang/String;

    move-result-object v4

    invoke-static {v6, v4, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :goto_0

    .line 50
    .end local v0           #e:Ljava/io/IOException;
    .end local v2           #fo:Ljava/io/FileOutputStream;
    .end local v3           #footList:Ljava/util/ArrayList;,"Ljava/util/ArrayList<Lcom/htc/android/footprints/vo/Footprint;>;"
    .restart local v1       #fo:Ljava/io/FileOutputStream;
    :catch_1
    move-exception v4

    move-object v0, v4

    .line 51
    .local v0, e:Ljava/lang/Exception;
    :goto_1
    :try_start_3
    new-instance v4, Ljava/lang/RuntimeException;

    invoke-direct {v4, v0}, Ljava/lang/RuntimeException;-><init>(Ljava/lang/Throwable;)V

    throw v4
    :try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_0

    .line 53
    .end local v0           #e:Ljava/lang/Exception;
    :catchall_0
    move-exception v4

    :goto_2
    if-eqz v1, :cond_1

    .line 55
    :try_start_4
    invoke-virtual {v1}, Ljava/io/FileOutputStream;->close()V
    :try_end_4
    .catch Ljava/io/IOException; {:try_start_4 .. :try_end_4} :catch_2

    .line 58
    :cond_1
    :goto_3
    throw v4

    .line 56
    :catch_2
    move-exception v0

    .line 57
    .local v0, e:Ljava/io/IOException;
    const-string v5, "FootprintRestoreService"

    invoke-virtual {v0}, Ljava/io/IOException;->getMessage()Ljava/lang/String;

    move-result-object v5

    invoke-static {v6, v5, v0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)I

    goto :goto_3

    .line 53
    .end local v0           #e:Ljava/io/IOException;
    .end local v1           #fo:Ljava/io/FileOutputStream;
    .restart local v2       #fo:Ljava/io/FileOutputStream;
    :catchall_1
    move-exception v4

    move-object v1, v2

    .end local v2           #fo:Ljava/io/FileOutputStream;
    .restart local v1       #fo:Ljava/io/FileOutputStream;
    goto :goto_2

    .line 50
    .end local v1           #fo:Ljava/io/FileOutputStream;
    .restart local v2       #fo:Ljava/io/FileOutputStream;
    :catch_3
    move-exception v4

    move-object v0, v4

    move-object v1, v2

    .end local v2           #fo:Ljava/io/FileOutputStream;
    .restart local v1       #fo:Ljava/io/FileOutputStream;
    goto :goto_1
.end method
